
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class PlayMonopoly extends JPanel
{	
	private int numHumanPlayers; // holds the number of human players
	private Player p1, p2, p3, p4;// represents the 4 game players (human and computer)
	private LayeredGameBoardPanel lgbp; // the game board
	private SideMenuPanel sidePanel; // the side menu
	
	private ChanceDeck chanceDeck; // the deck of chance cards
	private CommunityChestDeck commDeck; // the deck of community chest cards
	
	private int freeParkingFund;
	private int numBankruptPlayers; // if more than 1, game is over
	private int totalNumTurns;
	private final int TOTALNUMTURNS = 30;
		
	private GameLot [] masterArray; // array to hold all vital information about each property on the game board
	private final int NUMBOARDLOCATIONS = 40; // number of total spaces on the game board
	
	private final int INITIALCASHVALUE = 1500; // players' starting cash amount
	private final int GOCASH = 200; // amount of money for passing or landing on Go
	
	private int oldLocation = 0, newLocation = 0; // used to determine if a player has passed Go
	
	// some variables to make stuff happen easier for gameplay
	private GameLot curProp; // current GameLot object corresponding to a current player's location on a given turn
	private int curPlayerNum; // number of the current player during the game loop
	private Player curPlayer;  // Player object representing the current player during their turn
	private PurchasePanel purPan; // pops up for purchasing a property
	private TaxPanel taxPan; // pops up for dealing with tax lots
	private CardDrawPanel cdPan; // pops up for handling chance and community chest card draws
	private JailPanel jailPan; // pops up for handling options for a player in jail

	private boolean doublesWasRolled;
	private boolean stillInJail;
	private boolean justOutOfJailWithDoubles;
	

	public PlayMonopoly(BoardAndMenuPanel bmp)
	{
		lgbp = bmp.getLGBP();
		sidePanel = bmp.getSMP();
		
		chanceDeck = new ChanceDeck();
		commDeck = new CommunityChestDeck();
		
		// create Player objects and assign names to them
		p1 = new Player();
		p2 = new Player();
		p3 = new Player();
		p4 = new Player();
		
		masterArray = new GameLot[NUMBOARDLOCATIONS];
		initBoardLocations(masterArray);

		freeParkingFund = 0;
		numBankruptPlayers = 0;
		totalNumTurns = 0;
		doublesWasRolled = false;
		stillInJail = false;
		justOutOfJailWithDoubles = false;
		
		PreGameSetup();
		GamePlay();
	}
	
	public void PreGameSetup()
	{
		String numPlayersStr = null; // string to contain user input for number of human players
		numHumanPlayers = 0;
		Object [] choices = {"1", "2", "3", "4"}; // array to select number of human players
		String sString1 = ""; // used for adding an 's' to Player in the dialog window if there is more than 1
		String sString2 = ""; // used for adding an 's' to Opponent in the dialog window if there is more than 1
		
		// Strings for temporarily holding player name input
		String name1 = "", name2 = "", name3 = "", name4 = "";
		
		// ask for number of human players; will also determine # of computer opponents
		do
		{
			numPlayersStr = (String)JOptionPane.showInputDialog(null, "Select number of human players", 
								"Number of Players", JOptionPane.PLAIN_MESSAGE, null, choices, "1");
		} while(numPlayersStr == null);
		
		if(numPlayersStr == "1")
			numHumanPlayers = 1;
		else if(numPlayersStr == "2")
			numHumanPlayers = 2;
		else if(numPlayersStr == "3")
			numHumanPlayers = 3;
		else if(numPlayersStr == "4")
			numHumanPlayers = 4;
		
		if(numHumanPlayers > 1)
			sString1 = "s";
		if(numHumanPlayers != 3)
			sString2 = "s";
		
		JOptionPane.showMessageDialog(null, "You have chosen " + numHumanPlayers + " human player" + sString1 + "."
										+ "\nYou will have " + (4-numHumanPlayers) + " computer opponent" + sString2 + ".");
		
		
		
		
		String returnStr = null; // to hold input from dialog window
		
		// Get human player 1's name (there is always a minimum of 1 human player)
		do
		{
			returnStr = JOptionPane.showInputDialog(null, "Enter name for Player 1:");
		
			if (returnStr == null) // click ok with no entry
			{
				int returnInt = JOptionPane.showConfirmDialog(null, "You must enter a name to continue."
						+ "\nContinue?");
				if(returnInt == JOptionPane.NO_OPTION || returnInt == JOptionPane.CLOSED_OPTION)
				{
					JOptionPane.showMessageDialog(null, "Goodbye!");
					System.exit(0);
				}
			}
			else if (returnStr.equals("")) // click cancel
			{
				int returnInt = JOptionPane.showConfirmDialog(null, "You must enter a name to continue."
										+ "\nContinue?");
				if(returnInt == JOptionPane.NO_OPTION || returnInt == JOptionPane.CLOSED_OPTION)
				{
					JOptionPane.showMessageDialog(null, "Goodbye!");
					System.exit(0);
				}
			}
			else if (isBlank(returnStr) == true)
			{
				JOptionPane.showMessageDialog(null, "You must enter at least one character for a name.");
				returnStr = null;
			}
			else
			{
				name1 = returnStr; // name input successful
				break;
			}
		}while(returnStr != null || returnStr != "");
		
		// if more than 1 human player, ask for the 2nd human player's name:
		if(numHumanPlayers > 1)
		{
			do
			{
				returnStr = JOptionPane.showInputDialog(null, "Enter name for Player 2:");
				
				if (returnStr == null) // click ok with no entry
				{
					int returnInt = JOptionPane.showConfirmDialog(null, "You must enter a name to continue."
							+ "\nContinue?");
					if(returnInt == JOptionPane.NO_OPTION || returnInt == JOptionPane.CLOSED_OPTION)
					{
						JOptionPane.showMessageDialog(null, "Goodbye!");
						System.exit(0);
					}
				}
				else if (returnStr.equals("")) // click cancel
				{
					int returnInt = JOptionPane.showConfirmDialog(null, "You must enter a name to continue."
											+ "\nContinue?");
					if(returnInt == JOptionPane.NO_OPTION || returnInt == JOptionPane.CLOSED_OPTION)
					{
						JOptionPane.showMessageDialog(null, "Goodbye!");
						System.exit(0);
					}
				}
				else if (isBlank(returnStr) == true)
				{
					JOptionPane.showMessageDialog(null, "You must enter at least one character for a name.");
					returnStr = null;
				}
				else
				{
					name2 = returnStr;
					break;
				}
			}while(returnStr != null || returnStr != "");
		} // end if
		
		// if more than 2 human players, ask for the 3rd human player's name:
		if(numHumanPlayers > 2)
		{
			do
			{
				returnStr = JOptionPane.showInputDialog(null, "Enter name for Player 3:");
				
				if (returnStr == null) // click ok with no entry
				{
					int returnInt = JOptionPane.showConfirmDialog(null, "You must enter a name to continue."
							+ "\nContinue?");
					if(returnInt == JOptionPane.NO_OPTION || returnInt == JOptionPane.CLOSED_OPTION)
					{
						JOptionPane.showMessageDialog(null, "Goodbye!");
						System.exit(0);
					}
				}
				else if (returnStr.equals("")) // click cancel
				{
					int returnInt = JOptionPane.showConfirmDialog(null, "You must enter a name to continue."
											+ "\nContinue?");
					if(returnInt == JOptionPane.NO_OPTION || returnInt == JOptionPane.CLOSED_OPTION)
					{
						JOptionPane.showMessageDialog(null, "Goodbye!");
						System.exit(0);
					}
				}
				else if (isBlank(returnStr) == true)
				{
					JOptionPane.showMessageDialog(null, "You must enter at least one character for a name.");
					returnStr = null;
				}
				else
				{
					name3 = returnStr;
					break;
				}
			}while(returnStr != null || returnStr != "");
		} // end if

		// if more than 3 human players, ask for the 4th human player's name:
		if(numHumanPlayers > 3)
		{
			do
			{
				returnStr = JOptionPane.showInputDialog(null, "Enter name for Player 4:");
				
				if (returnStr == null) // click ok with no entry
				{
					int returnInt = JOptionPane.showConfirmDialog(null, "You must enter a name to continue."
							+ "\nContinue?");
					if(returnInt == JOptionPane.NO_OPTION || returnInt == JOptionPane.CLOSED_OPTION)
					{
						JOptionPane.showMessageDialog(null, "Goodbye!");
						System.exit(0);
					}
				}
				else if (returnStr.equals("")) // click cancel
				{
					int returnInt = JOptionPane.showConfirmDialog(null, "You must enter a name to continue."
											+ "\nContinue?");
					if(returnInt == JOptionPane.NO_OPTION || returnInt == JOptionPane.CLOSED_OPTION)
					{
						JOptionPane.showMessageDialog(null, "Goodbye!");
						System.exit(0);
					}
				}
				else if (isBlank(returnStr) == true)
				{
					JOptionPane.showMessageDialog(null, "You must enter at least one character for a name.");
					returnStr = null;
				}
				else
				{
					name4 = returnStr;
					break;
				}
			}while(returnStr != null || returnStr != "");
		} // end if
		

		// if less than 4 human players, must assign random names for computer opponents
		if(numHumanPlayers == 1)
		{
			name2 = "Jason";
			name3 = "Takahiro";
			name4 = "Randall";
		}
		else if(numHumanPlayers == 2)
		{
			name3 = "Jason";
			name4 = "Takahiro";
		}
		else if(numHumanPlayers == 3)
		{
			name4 = "Jason";
		}
		
		
//----------------------------------------------------------------------------------
// SECTION FOR DICE ROLLING TO DETERMINE PLAYER ORDER
		
		// random number to determine order of play (like a dice roll)
		ArrayList<Integer> faceValueList = new ArrayList<Integer>();
		int [] faceValueArray = new int[4];
		faceValueArray[0] = (int)(Math.random() * 12) + 1;
		
		//System.out.println("fVA[0]: " + faceValueArray[0]);
		do
		{
			faceValueArray[1] = (int)(Math.random() * 12) + 1;
			
		}while(faceValueArray[1] == faceValueArray[0]);
		
		do
		{
			faceValueArray[2] = (int)(Math.random() * 12) + 1;
		}while(faceValueArray[2] == faceValueArray[1] || faceValueArray[2] == faceValueArray[0]);
		
		do
		{
			faceValueArray[3] = (int)(Math.random() * 12) + 1; 
		}while(faceValueArray[3] == faceValueArray[2] || faceValueArray[3] == faceValueArray[1] || faceValueArray[3] == faceValueArray[0]);
		
		
		JOptionPane.showMessageDialog(null, "Roll dice to determine player order:\n" + name1 + ":     " + faceValueArray[0] + "\n"
		              + name2 + ":     " + faceValueArray[1] + "\n" + name3 + ":     " + faceValueArray[2] + "\n" + name4 
		              + ":     " + faceValueArray[3]);
		
		// copy faceValueArray into faceValueList
		for(int i=0; i<4; i++)
		{
			faceValueList.add(faceValueArray[i]);
//			System.out.println("fVL[" + i + "]: " + faceValueArray[i]);
		}
		
		// search faceValue ArrayList for highest value
		int max = 0;
		int index = 0;
		
		int [] newNameOrder = new int[4];

		for(int j=0; j<4; j++)
		{
			max = faceValueList.get(0);
			for(int i=0; i<faceValueList.size()-1; i++)
			{
				if(faceValueList.get(i+1) > max)
				{
					max = faceValueList.get(i+1);
				}			
			}
			//System.out.println("max: " + j);
			index = faceValueList.indexOf(max);
			newNameOrder[j] = index;
			faceValueList.remove(index);
			faceValueList.add(index, 0);
			
/*			
			for(int k=0; k<4; k++)
			{
				System.out.println("FVL array[" + j + "]: " + faceValueList.get(k));
			}
			System.out.println();
*/		
		} // end for(int j...)
/*				
		for(int i=0; i<4; i++)
		{
			System.out.println("newNameOrder[" + i + "]: " + newNameOrder[i]);
		}
*/		
// END OF SECTION
//----------------------------------------------------------------------------------

		// set player names and order
		for(int i=0; i<4; i++)
		{
			if(newNameOrder[i] == 0)
			{
				if(i == 0)
				{	p1.setPlayerName(name1);
					p1.setPlayerNumber(1);
				}
				else if(i == 1)
				{	p2.setPlayerName(name1);
					p2.setPlayerNumber(2);				
				}
				else if(i == 2)
				{	p3.setPlayerName(name1);
					p3.setPlayerNumber(3);
				}
				else if(i == 3)
				{	p4.setPlayerName(name1);
					p4.setPlayerNumber(4);
				}
			}
			else if(newNameOrder[i] == 1)
			{
				if(i == 0)
				{	p1.setPlayerName(name2);
					p1.setPlayerNumber(1);
				}
				else if(i == 1)
				{	p2.setPlayerName(name2);
					p2.setPlayerNumber(2);				
				}
				else if(i == 2)
				{	p3.setPlayerName(name2);
					p3.setPlayerNumber(3);
				}
				else if(i == 3)
				{	p4.setPlayerName(name2);
					p4.setPlayerNumber(4);
				}
			}
			else if(newNameOrder[i] == 2)
			{
				if(i == 0)
				{	p1.setPlayerName(name3);
					p1.setPlayerNumber(1);
				}
				else if(i == 1)
				{	p2.setPlayerName(name3);
					p2.setPlayerNumber(2);				
				}
				else if(i == 2)
				{	p3.setPlayerName(name3);
					p3.setPlayerNumber(3);
				}
				else if(i == 3)
				{	p4.setPlayerName(name3);
					p4.setPlayerNumber(4);
				}
			}
			else if(newNameOrder[i] == 3)
			{
				if(i == 0)
				{	p1.setPlayerName(name4);
					p1.setPlayerNumber(1);
				}
				else if(i == 1)
				{	p2.setPlayerName(name4);
					p2.setPlayerNumber(2);				
				}
				else if(i == 2)
				{	p3.setPlayerName(name4);
					p3.setPlayerNumber(3);
				}
				else if(i == 3)
				{	p4.setPlayerName(name4);
					p4.setPlayerNumber(4);
				}
			}
		} // end for
		
		sidePanel.setPlayerName(p1.getPlayerName(), p1.getPlayerNumber());
		sidePanel.setPlayerName(p2.getPlayerName(), p2.getPlayerNumber());
		sidePanel.setPlayerName(p3.getPlayerName(), p3.getPlayerNumber());
		sidePanel.setPlayerName(p4.getPlayerName(), p4.getPlayerNumber());
		
		sidePanel.setCashValue(INITIALCASHVALUE, 1);
		sidePanel.setCashValue(INITIALCASHVALUE, 2);
		sidePanel.setCashValue(INITIALCASHVALUE, 3);
		sidePanel.setCashValue(INITIALCASHVALUE, 4);
		
		sidePanel.setTotalWealth(INITIALCASHVALUE, 1);
		sidePanel.setTotalWealth(INITIALCASHVALUE, 2);
		sidePanel.setTotalWealth(INITIALCASHVALUE, 3);
		sidePanel.setTotalWealth(INITIALCASHVALUE, 4);		
		
		
		System.out.println("Player " + p1.getPlayerNumber() + "'s name: " + p1.getPlayerName());
		System.out.println("Player " + p2.getPlayerNumber() + "'s name: " + p2.getPlayerName());
		System.out.println("Player " + p3.getPlayerNumber() + "'s name: " + p3.getPlayerName());
		System.out.println("Player " + p4.getPlayerNumber() + "'s name: " + p4.getPlayerName());

	} // end PreGameSetup

	
	
	public void GamePlay()
	{
		// initialize first player
		curPlayer = p1; // initially set the current player to player 1, will update each game loop
		curPlayerNum = curPlayer.getPlayerNumber(); // current player of turn
		sidePanel.setTradeButton(true);
		sidePanel.setMortgageButton(true);
		sidePanel.setUnmortgageButton(true);
		sidePanel.setBuildButton(true);

// TEST:		
		p1.addNewProperty(masterArray[31]);
		p1.addNewProperty(masterArray[32]);
		p1.addNewProperty(masterArray[34]);
		
		masterArray[31].setOwnedBy(1);
		masterArray[32].setOwnedBy(1);
		masterArray[34].setOwnedBy(1);
		
		sidePanel.addProperty(masterArray[31].getName(), 1);
		sidePanel.addProperty(masterArray[32].getName(), 1);
		sidePanel.addProperty(masterArray[34].getName(), 1);
// END TEST
		
		
		/////////////////////////////////////////
		// WHILE LOOP STRUCTURE NEEDS TO GO HERE
		/////////////////////////////////////////
		
		do
		{
// CHECK FOR JAIL STATES---------------------------------------------------------------------------------------------------------

		//TEST:
		//curPlayer.setJailState(true);
		//END TEST

		// alert player it is their turn:
		System.out.println(curPlayer.getPlayerName() + "(P" + curPlayer.getPlayerNumber() + ")'s turn.");
		JOptionPane.showMessageDialog(null, "Player " + curPlayerNum + "'s turn!");
		
			
		// if player is in jail and # of jail turns is 3, pay fine and get out of jail
		// and proceed as normal
		if(curPlayer.getJailState() == true)
		{
			JOptionPane.showMessageDialog(null, "Player " + curPlayer.getPlayerNumber() + " is currently in Jail!");
			sidePanel.setRollButtonState(false);
			curPlayer.increaseJailTurns();
			processJailOptions();
		}
		if(stillInJail == true)
		{
			if(curPlayer.getPlayerNumber() == 1)
			{
				curPlayer = p2;
				curPlayerNum = 2;
			}
			else if(curPlayer.getPlayerNumber() == 2)
			{
				curPlayer = p3;
				curPlayerNum = 3;
			}
			else if(curPlayer.getPlayerNumber() == 3)
			{
				curPlayer = p4;
				curPlayerNum = 4;
			}
			else if(curPlayer.getPlayerNumber() == 4)
			{
				curPlayer = p1;
				curPlayerNum = 1;
				totalNumTurns++;
			}
			stillInJail = false;
			continue;
		}

// END CHECK FOR JAIL STATES-----------------------------------------------------------------------------------------------------		
		
// PROCESS NORMAL TURN:----------------------------------------------------------------------------------------------------------		
		
		if(justOutOfJailWithDoubles == false)
		{
			sidePanel.setRollButtonState(true);
			sidePanel.setCurPlayer(curPlayer);
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				
				// check for roll button
				if(rollButtonClicked() == true)
				{
					sidePanel.resetRollButtonClicked();
					sidePanel.setRollButtonState(false);
					// not sure about setting states for these here:
					/*
					sidePanel.setBuildButton(false);
					sidePanel.setTradeButton(false);
					sidePanel.setMortgageButton(false);
					sidePanel.setUnmortgageButton(false);
					sidePanel.setEndTurnButton(false);
					*/
					
					// wait so dice animation can finish rolling before assigning the new dice value
					while(true)
					{
						System.out.print(""); // statement added so Michael's code will work properly
						if(sidePanel.rollIsDone() == true)
						{
							break;
						}
					}
					
					break;
				}
				// check for build button
				if(sidePanel.buildButtonClicked() == true)
				{	
					while(true)
					{
						System.out.print(""); // statement added so Michael's code will work properly
						if(sidePanel.getBuildReturnValue() == 1)
						{
							System.out.println("BUILT something");
							new CheckAndUpdatePlayerBuildings(curPlayer, lgbp);
							sidePanel.resetBuildReturnValue();
							sidePanel.resetBuildClicked();
							break;
						}
						else if(sidePanel.getBuildReturnValue() == 0)
						{
							System.out.println("did not BUILD");
							sidePanel.resetBuildReturnValue();
							sidePanel.resetBuildClicked();
							break;
						}
					} // end while
					// don't need to break???					
				} // end if for buildButtonClicked
				
				if(sidePanel.mortgageButtonClicked() == true)
				{
					while(true)
					{
						System.out.print(""); // statement added so Michael's code will work properly
						if(sidePanel.getMortgageReturnValue() == 1)
						{
							System.out.println("MORTGAGED something");
							//new CheckAndUpdatePlayerBuildings(curPlayer, lgbp);
							sidePanel.resetMortgageReturnValue();
							sidePanel.resetMortgageClicked();
							break;
						}
						else if(sidePanel.getMortgageReturnValue() == 0)
						{
							System.out.println("did not MORTGAGE");
							sidePanel.resetMortgageReturnValue();
							sidePanel.resetMortgageClicked();
							break;
						}
					} // end while
				} // end if for mortgageButtonClicked
				
/*				
				if(sidePanel.tradeButtonClicked() == true)
				{

				}
				
				if(sidePanel.unmortgageButtonClicked() == true)
				{

				}
				
				if(sidePanel.endTurnButtonClicked() == true)
				{

				}
				
				if(sidePanel.quitButtonClicked() == true)
				{

				}
*/				
			
// CHECK FOR ALL OTHER BUTTONS BEING CLICKED ALSO
// trade, mortgage/sell, unmortgage, end turn, quit
			
			} // end while
		

			// check for doubles rolled and process accordingly
			if(sidePanel.diceIsDoubles() == false)
			{
				curPlayer.resetDoublesRolled();
				doublesWasRolled = false;
			}
			else if(sidePanel.diceIsDoubles() == true)
			{
				System.out.println("doubles was rolled");
				doublesWasRolled = true;
				
				if(curPlayer.getPlayerNumber() == 1)
				{
					curPlayer.increaseDoublesRolled();
					if(curPlayer.getDoublesRolled() == 3)
					{
						JOptionPane.showMessageDialog(null, "Three doubles in a row."
								+ "\nGo directly to Jail.\nDo not pass Go.  Do not collect $" + GOCASH);
						curPlayer.setLocation(10);
						curPlayer.setJailState(true);
						curPlayer.resetDoublesRolled();
						doublesWasRolled = false;
						lgbp.movePawn(40, curPlayer.getPlayerNumber());
						waitForPawnToMove();
						curPlayer = p2;
						// need to repeat overall game loop here using continue
						continue;
					}
				}
				else if(curPlayer.getPlayerNumber() == 2)
				{
					curPlayer.increaseDoublesRolled();
					if(curPlayer.getDoublesRolled() == 3)
					{
						JOptionPane.showMessageDialog(null, "Three doubles in a row."
								+ "\nGo directly to Jail.\nDo not pass Go.  Do not collect $" + GOCASH);
						curPlayer.setLocation(10);
						curPlayer.setJailState(true);
						curPlayer.resetDoublesRolled();
						doublesWasRolled = false;
						lgbp.movePawn(40, curPlayer.getPlayerNumber());
						curPlayer = p3;
						// need to repeat overall game loop here using continue
						continue;
					}
				}
				else if(curPlayer.getPlayerNumber() == 3)
				{
					curPlayer.increaseDoublesRolled();
					if(curPlayer.getDoublesRolled() == 3)
					{
						JOptionPane.showMessageDialog(null, "Three doubles in a row."
								+ "\nGo directly to Jail.\nDo not pass Go.  Do not collect $" + GOCASH);
						curPlayer.setLocation(10);
						curPlayer.setJailState(true);
						curPlayer.resetDoublesRolled();
						doublesWasRolled = false;
						lgbp.movePawn(40, curPlayer.getPlayerNumber());
						waitForPawnToMove();
						curPlayer = p4;
						// need to repeat overall game loop here using continue
						continue;
					}
				}
				else if(curPlayer.getPlayerNumber() == 4)
				{
					curPlayer.increaseDoublesRolled();
					if(curPlayer.getDoublesRolled() == 3)
					{
						JOptionPane.showMessageDialog(null, "Three doubles in a row."
								+ "\nGo directly to Jail.\nDo not pass Go.  Do not collect $" + GOCASH);
						curPlayer.setLocation(10);
						curPlayer.setJailState(true);
						curPlayer.resetDoublesRolled();
						doublesWasRolled = false;
						lgbp.movePawn(40, curPlayer.getPlayerNumber());
						waitForPawnToMove();
						curPlayer = p1;
						totalNumTurns++;
						// need to repeat overall game loop here using continue
						continue;
					}
				}
				
			} // end else if diceIsDoubles == true...
		
		} // end if(justOutOfJailWithDoubles == false)
		
		justOutOfJailWithDoubles = false;
		
		// set curPlayerNum based on results above
		curPlayerNum = curPlayer.getPlayerNumber();
		


		// once dice Roll button clicked, set player location to new location
		// based on the value of the dice, but must keep up with old location also
		// to see if Go is passed
		oldLocation = curPlayer.getLocation();
		System.out.println("Player " + curPlayer.getPlayerNumber() + "'s OLD location: " + oldLocation
				+ "(" + masterArray[oldLocation].getName() + ")");
		
		//curPlayer.setLocation(2); // temp to test pop up panel									//HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		curPlayer.setLocation(curPlayer.getLocation() + getDiceValue());
		

		lgbp.movePawn(curPlayer.getLocation(), curPlayer.getPlayerNumber());
		waitForPawnToMove();
		
		System.out.println("dice value: " + getDiceValue());
		
		newLocation = curPlayer.getLocation();
		curProp = masterArray[curPlayer.getLocation()];
		
		System.out.println("Player " + curPlayer.getPlayerNumber() + "'s NEW location: " + newLocation
				+ "(" + curProp.getName() + ")");
		
		
		// this is for when a player passes Go
		if(oldLocation >= 28 && newLocation <= 11 && curPlayer.getJailState() == false)
		{
			passedGo(curPlayer, sidePanel);
		}
				
		System.out.println("cur location: " + curProp.getName());
		System.out.println("loc type: " + masterArray[curPlayer.getLocation()].getType());		

//RAILROAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if(curProp.getType() == "railroad")
		{
			processLandingOnRailroad(false);
		}
//PROPERTY///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		else if(curProp.getType() == "property")
		{
			processLandingOnProperty(false);
		}
//UTILITY////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		else if(curProp.getType() == "utility")
		{
			processLandingOnUtility(false);
		} // end if for utility
//CORNER/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		else if(curProp.getType() == "corner")
		{
			processLandingOnCorner();
		}
//TAX////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		else if(curProp.getType() == "tax")
		{
			processLandingOnTax(false);
		} // end else if for type tax
//CHANCE/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		else if(curProp.getName() == "Chance")
		{
			processLandingOnChance();
		}
//COMMUNITY CHEST////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		else if(curProp.getName() == "CommunityChest")
		{
			processLandingOnCommunityChest();
		}

		checkIfDoublesWasRolled();
		

		System.out.println("CurrentPlayer: " + curPlayer.getPlayerNumber());
		System.out.println("totalNumTurns: " + totalNumTurns);
		
		
		}while(numBankruptPlayers < 2 || totalNumTurns < TOTALNUMTURNS);
		
	} // end GamePlay
//-------------------------------------------------------------------------------------------------------------------------------	

	public boolean rollButtonClicked()
	{
		return sidePanel.rollButtonClicked();
	}
	
//-------------------------------------------------------------------------------------------------------------------------------	

	public int getDiceValue()
	{
		return sidePanel.getDiceValue();
	}
		
//-------------------------------------------------------------------------------------------------------------------------------	

	public boolean isBlank(String str)
	{
		if(str.length() == 0 || str == null)
			return true;
		else
		{
			for(int i=0; i<str.length(); i++)
			{
				if(str.charAt(i) != ' ')
					return false;					
			}
			return true;
		}
	}
	
//-------------------------------------------------------------------------------------------------------------------------------	

	public void initBoardLocations(GameLot [] ma)
	{
		ma[0] = new GameLot("Go");
		ma[1] = new GameLot("MediterraneanAve");
		ma[2] = new GameLot("CommunityChest");
		ma[3] = new GameLot("BalticAve");
		ma[4] = new GameLot("IncomeTax");
		ma[5] = new GameLot("ReadingRailroad");
		ma[6] = new GameLot("OrientalAve");
		ma[7] = new GameLot("Chance");
		ma[8] = new GameLot("VermontAve");
		ma[9] = new GameLot("ConnecticutAve");
		ma[10] = new GameLot("Jail");
		ma[11] = new GameLot("StCharlesPlace");
		ma[12] = new GameLot("ElectricCompany");
		ma[13] = new GameLot("StatesAve");
		ma[14] = new GameLot("VirginiaAve");
		ma[15] = new GameLot("PennsylvaniaRailroad");
		ma[16] = new GameLot("StJamesPlace");
		ma[17] = new GameLot("CommunityChest");
		ma[18] = new GameLot("TennesseeAve");
		ma[19] = new GameLot("NewYorkAve");
		ma[20] = new GameLot("FreeParking");
		ma[21] = new GameLot("KentuckyAve");
		ma[22] = new GameLot("Chance");
		ma[23] = new GameLot("IndianaAve");
		ma[24] = new GameLot("IllinoisAve");
		ma[25] = new GameLot("B&ORailroad");
		ma[26] = new GameLot("AtlanticAve");
		ma[27] = new GameLot("VentnorAve");
		ma[28] = new GameLot("WaterWorks");
		ma[29] = new GameLot("MarvinGardens");
		ma[30] = new GameLot("GoToJail");
		ma[31] = new GameLot("PacificAve");
		ma[32] = new GameLot("NorthCarolinaAve");
		ma[33] = new GameLot("CommunityChest");
		ma[34] = new GameLot("PennsylvaniaAve");
		ma[35] = new GameLot("ShortLineRailroad");
		ma[36] = new GameLot("Chance");
		ma[37] = new GameLot("ParkPlace");
		ma[38] = new GameLot("LuxuryTax");
		ma[39] = new GameLot("Boardwalk");
	}
	
//-------------------------------------------------------------------------------------------------------------------------------	

	public void setPlayerName(String name, int playerNum)
	{
		sidePanel.setPlayerName(name, playerNum);
	}
	
//-------------------------------------------------------------------------------------------------------------------------------	

	public void setCashValue(int value, int playerNum)
	{
		sidePanel.setCashValue(value, playerNum);
	}

//-------------------------------------------------------------------------------------------------------------------------------	

	public void setTotalWorth(int value, int playerNum)
	{
		sidePanel.setTotalWealth(value, playerNum);
	}

//-------------------------------------------------------------------------------------------------------------------------------

	public void processLandingOnChance()
	{
		//String name = "gotojail";
		String name = chanceDeck.getArrayList().get(0);
		System.out.println("name: " + name);
		
		cdPan = new CardDrawPanel(name, "chance");
		// display popup for drawing a chance card
		JFrame frame = new JFrame ("Draw Chance Card");
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().add(cdPan);
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setResizable(true);
		frame.setVisible(true);
		
		while(true)
		{
			System.out.print(""); // statement added so Michael's code will work properly
			if(cdPan.getReturnValue() == 1)
				break;
		}
		
		// handle the card action
		if(name == "back3spaces")
		{
			if(curPlayer.getLocation() >= 3)
			{
				curPlayer.setLocation(curPlayer.getLocation() - 3);
				lgbp.movePawn(curPlayer.getLocation() - 3, curPlayer.getPlayerNumber()); // NEEDS MOVE PAWN BACKWARDS FUNCTION
				waitForPawnToMove();
			}
			else if(curPlayer.getLocation() == 2)
			{
				curPlayer.setLocation(39);
				lgbp.movePawn(39, curPlayer.getPlayerNumber()); // NEEDS MOVE PAWN BACKWARDS FUNCTION
				waitForPawnToMove();
			}
			else if(curPlayer.getLocation() == 1)
			{
				curPlayer.setLocation(38);
				lgbp.movePawn(38, curPlayer.getPlayerNumber()); // NEEDS MOVE PAWN BACKWARDS FUNCTION
				waitForPawnToMove();
			}
			else if(curPlayer.getLocation() == 0)
			{
				curPlayer.setLocation(37);
				lgbp.movePawn(37, curPlayer.getPlayerNumber()); // NEEDS MOVE PAWN BACKWARDS FUNCTION
				waitForPawnToMove();
			}
			
			// now must process the new property landed on
			curProp = masterArray[curPlayer.getLocation()];
			if(curProp.getType() == "railroad")
			{
				processLandingOnRailroad(false); // must be false here b/c it's not the special railroad chance card
			}
			else if(curProp.getType() == "property")
			{
				processLandingOnProperty(true);
			}
			else if(curProp.getType() == "utility")
			{
				processLandingOnUtility(false); // must be false here b/c it's not the special utility chance card
			}
			else if(curProp.getType() == "corner")
			{
				processLandingOnCorner();
			}
			else if(curProp.getType() == "tax")
			{
				processLandingOnTax(true);
			}
			else if(curProp.getName() == "Chance")
			{
				processLandingOnChance();
			}
			else if(curProp.getName() == "CommunityChest")
			{
				processLandingOnCommunityChest();
			}
		}
		else if(name == "bank50")
		{
			curPlayer.addCash(50);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "boardwalk")
		{
			int oldLoc = curPlayer.getLocation();
			curPlayer.setLocation(39);
			lgbp.movePawn(39, curPlayer.getPlayerNumber());
			waitForPawnToMove();

			if(oldLoc == 39)
			{
				passedGo(curPlayer, sidePanel);
			}
			
			// this is to ensure the player sees the chance card before another window pops up
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				if(cdPan.getReturnValue() == 1)
					break;
			}
			
			curProp = masterArray[curPlayer.getLocation()];
			processLandingOnProperty(true);
		}
		else if(name == "chairman")
		{
			curPlayer.subtractCash(150);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());

			if(curPlayer.getPlayerNumber() == 1)
			{
				p2.addCash(50);
				p3.addCash(50);
				p4.addCash(50);
				sidePanel.setCashValue(p2.getCash(), 2);
				sidePanel.setCashValue(p3.getCash(), 3);
				sidePanel.setCashValue(p4.getCash(), 4);
			}
			else if(curPlayer.getPlayerNumber() == 2)
			{
				p1.addCash(50);
				p3.addCash(50);
				p4.addCash(50);
				sidePanel.setCashValue(p1.getCash(), 1);
				sidePanel.setCashValue(p3.getCash(), 3);
				sidePanel.setCashValue(p4.getCash(), 4);
			}
			else if(curPlayer.getPlayerNumber() == 3)
			{
				p1.addCash(50);
				p2.addCash(50);
				p4.addCash(50);
				sidePanel.setCashValue(p1.getCash(), 1);
				sidePanel.setCashValue(p2.getCash(), 2);
				sidePanel.setCashValue(p4.getCash(), 4);

			}
			else if(curPlayer.getPlayerNumber() == 4)
			{
				p1.addCash(50);
				p2.addCash(50);
				p3.addCash(50);
				sidePanel.setCashValue(p1.getCash(), 1);
				sidePanel.setCashValue(p2.getCash(), 2);
				sidePanel.setCashValue(p3.getCash(), 3);
			}

			sidePanel.setTotalWealth(p1.getTotalWealth(), 1);
			sidePanel.setTotalWealth(p2.getTotalWealth(), 2);
			sidePanel.setTotalWealth(p3.getTotalWealth(), 3);
			sidePanel.setTotalWealth(p4.getTotalWealth(), 4);
		}
		else if(name == "go")
		{
			curPlayer.setLocation(0);
			lgbp.movePawn(0, curPlayer.getPlayerNumber());
			waitForPawnToMove();
			passedGo(curPlayer, sidePanel);	
		}
		else if(name == "gotojail")
		{
			JOptionPane.showMessageDialog(null, "Go directly to Jail.\nDo not pass Go.  Do not collect $" + GOCASH);
			curPlayer.setLocation(10);
			curPlayer.setJailState(true);
			curPlayer.resetDoublesRolled();
			doublesWasRolled = false;
			lgbp.movePawn(40, curPlayer.getPlayerNumber()); // use 40 for special pawn movement in LayeredGameBoardPanel
			waitForPawnToMove();
			
			
			System.out.println("curPlayer: " + curPlayer.getPlayerNumber());
			System.out.println("curPlayer Location: " + curPlayer.getLocation());
			System.out.println("curPlayer Jail State: " + curPlayer.getJailState());

			
			
		}
		else if(name == "illinois")
		{
			int oldLoc = curPlayer.getLocation();
			curPlayer.setLocation(24);
			lgbp.movePawn(24, curPlayer.getPlayerNumber());
			waitForPawnToMove();
			if(oldLoc >= 24)
			{
				passedGo(curPlayer, sidePanel);
			}
			
			// this is to ensure the player sees the chance card before another window pops up
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				if(cdPan.getReturnValue() == 1)
					break;
			}
			
			curProp = masterArray[curPlayer.getLocation()];
			processLandingOnProperty(true);			
		}
		else if(name == "jailfreechance")
		{
			curPlayer.setJailFreeChance(true);
			sidePanel.addJailFreeCard(name, curPlayer.getPlayerNumber());
		}
		else if(name == "loanmatures")
		{
			curPlayer.addCash(150);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "nearestutility")
		{
			if(curPlayer.getLocation() < 12)
			{
				curPlayer.setLocation(12);
				lgbp.movePawn(12, curPlayer.getPlayerNumber());
				waitForPawnToMove();
			}
			else if(curPlayer.getLocation() >= 12 && curPlayer.getLocation() < 28)
			{
				curPlayer.setLocation(28);
				lgbp.movePawn(28, curPlayer.getPlayerNumber());
				waitForPawnToMove();
			}
			else if(curPlayer.getLocation() >= 28)
			{
				curPlayer.setLocation(12);
				lgbp.movePawn(12, curPlayer.getPlayerNumber());
				waitForPawnToMove();
				passedGo(curPlayer, sidePanel);
			}
			
			// this is to ensure the player sees the chance card before another window pops up
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				if(cdPan.getReturnValue() == 1)
					break;
			}
			
			curProp = masterArray[curPlayer.getLocation()];
			processLandingOnUtility(true);
		}
		else if(name == "nearrailroad" || name == "railroad2")
		{
			int curLoc = curPlayer.getLocation();
			
			if(curLoc < 5)
			{
				curPlayer.setLocation(5);
				lgbp.movePawn(5, curPlayer.getPlayerNumber());
				waitForPawnToMove();
			}
			else if(curLoc >= 5 && curLoc < 15)
			{
				curPlayer.setLocation(15);
				lgbp.movePawn(15, curPlayer.getPlayerNumber());
				waitForPawnToMove();
			}
			else if(curLoc >= 15 && curLoc < 25)
			{
				curPlayer.setLocation(25);
				lgbp.movePawn(25, curPlayer.getPlayerNumber());
				waitForPawnToMove();
			}
			else if(curLoc >= 25 && curLoc < 35)
			{
				curPlayer.setLocation(35);
				lgbp.movePawn(35, curPlayer.getPlayerNumber());
				waitForPawnToMove();
			}
			else if(curLoc >= 35)
			{
				curPlayer.setLocation(5);
				lgbp.movePawn(5, curPlayer.getPlayerNumber());
				waitForPawnToMove();
				passedGo(curPlayer, sidePanel);
			}
			
			// this is to ensure the player sees the chance card before another window pops up
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				if(cdPan.getReturnValue() == 1)
					break;
			}
			
			curProp = masterArray[curPlayer.getLocation()];
			processLandingOnRailroad(true);
		}
		else if(name == "poortax")
		{
			freeParkingFund += 15;
			curPlayer.subtractCash(15);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "reading")
		{
			int curLoc = curPlayer.getLocation();
			
			if(curLoc < 5)
			{
				curPlayer.setLocation(5);
				lgbp.movePawn(5, curPlayer.getPlayerNumber());
				waitForPawnToMove();
			}
			else if(curLoc >= 5)
			{
				curPlayer.setLocation(5);
				lgbp.movePawn(5, curPlayer.getPlayerNumber());
				waitForPawnToMove();
				passedGo(curPlayer, sidePanel);
			}
			
			// this is to ensure the player sees the chance card before another window pops up
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				if(cdPan.getReturnValue() == 1)
					break;
			}
			
			curProp = masterArray[curPlayer.getLocation()];
			processLandingOnRailroad(false); // must be false here b/c it's not the special railroad chance card
		}
		else if(name == "repairs")
		{
			int houses = curPlayer.getTotalHouseNum();
			int hotels = curPlayer.getTotalHotelNum();
			int fee = (houses*25) + (hotels*100);
			freeParkingFund += fee;
			curPlayer.subtractCash(fee);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "stcharles")
		{
			int oldLoc = curPlayer.getLocation();
			curPlayer.setLocation(11);
			lgbp.movePawn(11, curPlayer.getPlayerNumber());
			waitForPawnToMove();
			if(oldLoc >= 11)
			{
				passedGo(curPlayer, sidePanel);
			}
			
			// this is to ensure the player sees the chance card before another window pops up
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				if(cdPan.getReturnValue() == 1)
					break;
			}
			
			curProp = masterArray[curPlayer.getLocation()];
			processLandingOnProperty(true);
		}
		
		// update deck by putting top card on the bottom
		chanceDeck.frontToBack(chanceDeck.getArrayList());
		cdPan.resetReturnValue();
		wait(2500); // so card doesn't go away immediately upon it appearing
		frame.setVisible(false);
		frame.dispose();
		
		name = chanceDeck.getArrayList().get(0);
		System.out.println("name: " + name);
		
	} // end processLandingOnChance

//-------------------------------------------------------------------------------------------------------------------------------	

	public void processLandingOnCommunityChest()
	{
		//String name = "gotojail";
		String name = commDeck.getArrayList().get(0);
		System.out.println("name: " + name);
					
		cdPan = new CardDrawPanel(name, "communitychest");
		// display popup for drawing a community chest card
		JFrame frame = new JFrame ("Draw Community Chest Card");
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().add(cdPan);
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setResizable(true);
		frame.setVisible(true);			
		
		while(true)
		{
			System.out.print(""); // statement added so Michael's code will work properly
			if(cdPan.getReturnValue() == 1)
				break;
		}
		
		// handle card action
		if(name == "bankerror")
		{
			curPlayer.addCash(200);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "contest")
		{
			curPlayer.addCash(10);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "fee")
		{
			curPlayer.subtractCash(50);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
			freeParkingFund += 50;
		}
		else if(name == "go")
		{
			curPlayer.setLocation(0);
			lgbp.movePawn(0, curPlayer.getPlayerNumber());
			waitForPawnToMove();
			passedGo(curPlayer, sidePanel);
		}
		else if(name == "gotojail")
		{
			JOptionPane.showMessageDialog(null, "Go directly to Jail.\nDo not pass Go.  Do not collect $" + GOCASH);
			curPlayer.setLocation(10);
			curPlayer.setJailState(true);
			curPlayer.resetDoublesRolled();
			doublesWasRolled = false;
			lgbp.movePawn(40, curPlayer.getPlayerNumber());
			waitForPawnToMove();
		}
		else if(name == "incometax")
		{
			curPlayer.addCash(20);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "inherit" || name == "insurancematures")
		{
			curPlayer.addCash(100);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "jailfreechest")
		{
			curPlayer.setJailFreeCommChest(true);
			sidePanel.addJailFreeCard(name, curPlayer.getPlayerNumber());
		}
		else if(name == "opera")
		{
			curPlayer.addCash(150);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());

			if(curPlayer.getPlayerNumber() == 1)
			{
				p2.subtractCash(50);
				p3.subtractCash(50);
				p4.subtractCash(50);
				sidePanel.setCashValue(p2.getCash(), 2);
				sidePanel.setCashValue(p3.getCash(), 3);
				sidePanel.setCashValue(p4.getCash(), 4);
			}
			else if(curPlayer.getPlayerNumber() == 2)
			{
				p1.subtractCash(50);
				p3.subtractCash(50);
				p4.subtractCash(50);
				sidePanel.setCashValue(p1.getCash(), 1);
				sidePanel.setCashValue(p3.getCash(), 3);
				sidePanel.setCashValue(p4.getCash(), 4);
			}
			else if(curPlayer.getPlayerNumber() == 3)
			{
				p1.subtractCash(50);
				p2.subtractCash(50);
				p4.subtractCash(50);
				sidePanel.setCashValue(p1.getCash(), 1);
				sidePanel.setCashValue(p2.getCash(), 2);
				sidePanel.setCashValue(p4.getCash(), 4);
			}
			else if(curPlayer.getPlayerNumber() == 4)
			{
				p1.subtractCash(50);
				p2.subtractCash(50);
				p3.subtractCash(50);
				sidePanel.setCashValue(p1.getCash(), 1);
				sidePanel.setCashValue(p2.getCash(), 2);
				sidePanel.setCashValue(p3.getCash(), 3);
			}
			
			sidePanel.setTotalWealth(p1.getTotalWealth(), 1);
			sidePanel.setTotalWealth(p2.getTotalWealth(), 2);
			sidePanel.setTotalWealth(p3.getTotalWealth(), 3);
			sidePanel.setTotalWealth(p4.getTotalWealth(), 4);
		}
		else if(name == "payhospital")
		{
			curPlayer.subtractCash(100);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
			freeParkingFund += 100;
		}
		else if(name == "repairs")
		{
			int houses = curPlayer.getTotalHouseNum();
			int hotels = curPlayer.getTotalHotelNum();
			int fee = (houses*40) + (hotels*115);
			freeParkingFund += fee;
			curPlayer.subtractCash(fee);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "schooltax")
		{
			curPlayer.subtractCash(150);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
			freeParkingFund += 150;
		}
		else if(name == "services")
		{
			curPlayer.addCash(25);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "stock")
		{
			curPlayer.addCash(45);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(name == "xmasfund")
		{
			curPlayer.addCash(100);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());			
		}
		
		// update deck by putting top card on the bottom
		commDeck.frontToBack(commDeck.getArrayList());
		cdPan.resetReturnValue();
		wait(2500); // so card doesn't go away immediately upon it appearing
		frame.setVisible(false);
		frame.dispose();

		name = commDeck.getArrayList().get(0);
		System.out.println("name: " + name);
	} // end processLandingOnCommunityChest
	
//-------------------------------------------------------------------------------------------------------------------------------

	public void passedGo(Player curP, SideMenuPanel smp)
	{
		JOptionPane.showMessageDialog(null, "You passed Go!  Collect $" + GOCASH);
		curP.addCash(GOCASH);
		curP.addTotalWealth(GOCASH);
		smp.setCashValue(curP.getCash(), curP.getPlayerNumber());
		smp.setTotalWealth(curP.getTotalWealth(), curP.getPlayerNumber());
	}

//-------------------------------------------------------------------------------------------------------------------------------
	
	public void processLandingOnRailroad(boolean fromChance)
	{
// TEST:
/*		curProp.setOwnedBy(3);
		p3.addNewProperty(curProp.getName());
		p3.addNewProperty("B&ORailroad");
		p3.addNewProperty("ShortLineRailroad");
		p3.addNewProperty("PennsylvaniaRailroad");
		sidePanel.addProperty(curProp.getName(), 3);

		sidePanel.addProperty("B&ORailroad", 3);
		sidePanel.addProperty("ShortLineRailroad", 3);
		sidePanel.addProperty("PennsylvaniaRailroad", 3);
// END TEST
*/		
		
		// process railroad code:
	
		// if current property is unowned
		if(curProp.getOwnedBy() == 0)
		{
			displayPurchaseWindow(fromChance);
		}
		
		// property is owned by another player
		else if(curProp.getOwnedBy() != 0)
		{
			if(curProp.getOwnedBy() == curPlayer.getPlayerNumber())
			{
				JOptionPane.showMessageDialog(null, "You already own this property!");
			}
			else
			{
				// calculate how much rent to pay owning player
				int owner = curProp.getOwnedBy();
				
				if(owner == 1)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + p1.getRailroadRent() + " for rent.");
					
					// if a chance card told you to land here then the rent is doubled
					if(fromChance == true)
					{	
						p1.addCash(p1.getRailroadRent() * 2);
						curPlayer.subtractCash(p1.getRailroadRent() * 2);
					}
					else if(fromChance == false)
					{
						p1.addCash(p1.getRailroadRent());
						curPlayer.subtractCash(p1.getRailroadRent());
					}
					
					sidePanel.setCashValue(p1.getCash(), owner);					
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(p1.getTotalWealth(), owner);
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
				}
				else if(owner == 2)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + p2.getRailroadRent() + " for rent.");
					
					// if a chance card told you to land here then the rent is doubled
					if(fromChance == true)
					{	
						p2.addCash(p2.getRailroadRent() * 2);
						curPlayer.subtractCash(p2.getRailroadRent() * 2);
					}
					else if(fromChance == false)
					{
						p2.addCash(p2.getRailroadRent());
						curPlayer.subtractCash(p2.getRailroadRent());
					}
					
					sidePanel.setCashValue(p2.getCash(), owner);					
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(p2.getTotalWealth(), owner);
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
				}
				else if(owner == 3)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + p3.getRailroadRent() + " for rent.");
					
					// if a chance card told you to land here then the rent is doubled
					if(fromChance == true)
					{	
						p3.addCash(p3.getRailroadRent() * 2);
						curPlayer.subtractCash(p3.getRailroadRent() * 2);
					}
					else if(fromChance == false)
					{
						p3.addCash(p3.getRailroadRent());
						curPlayer.subtractCash(p3.getRailroadRent());
					}
					
					sidePanel.setCashValue(p3.getCash(), owner);					
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(p3.getTotalWealth(), owner);
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
				}
				else if(owner == 4)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + p4.getRailroadRent() + " for rent.");
					
					// if a chance card told you to land here then the rent is doubled
					if(fromChance == true)
					{	
						p4.addCash(p4.getRailroadRent() * 2);
						curPlayer.subtractCash(p4.getRailroadRent() * 2);
					}
					else if(fromChance == false)
					{
						p4.addCash(p4.getRailroadRent());
						curPlayer.subtractCash(p4.getRailroadRent());
					}
					
					sidePanel.setCashValue(p4.getCash(), owner);					
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(p4.getTotalWealth(), owner);
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
				}
			} // end else
		} // end else if	
	} //end processLandingOnRailroad

//-------------------------------------------------------------------------------------------------------------------------------	

	public void processLandingOnProperty(boolean fromChance)
	{
// TEST:
/*		curProp.setOwnedBy(2);
		p2.addNewProperty(curProp.getName());
		p1.addNewProperty("ConnecticutAve");
		p1.addNewProperty("VermontAve");
		
		p2.buildHouse("VirginiaAve", 2);
		p2.buildHouse(curProp.getName(), 2);
		p2.buildHouse("StCharlesPlace", 2);

		sidePanel.addProperty(curProp.getName(), 2);
		sidePanel.addProperty("ConnecticutAve", 1);
		sidePanel.addProperty("VermontAve", 1);
*/
// END TEST
		
		
		// process property code:	
		
		// if current property is unowned
		if(curProp.getOwnedBy() == 0)
		{
			displayPurchaseWindow(fromChance);
		}
		// property is owned by another player
		else if(curProp.getOwnedBy() != 0)
		{
			if(curProp.getOwnedBy() == curPlayer.getPlayerNumber())
			{
				JOptionPane.showMessageDialog(null, "You already own this property!");
			}
			else
			{
				// calculate how much rent to pay owning player
				int owner = curProp.getOwnedBy();
				
				if(owner == 1)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + p1.getRentValue(curProp.getName(), curProp.getColor()) + " for rent.");
					
					p1.addCash(p1.getRentValue(curProp.getName(), curProp.getColor()));
					sidePanel.setCashValue(p1.getCash(), owner);
					
					curPlayer.subtractCash(p1.getRentValue(curProp.getName(), curProp.getColor()));
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(p1.getTotalWealth(), owner);
				}
				else if(owner == 2)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + p2.getRentValue(curProp.getName(), curProp.getColor()) + " for rent.");
					
					p2.addCash(p2.getRentValue(curProp.getName(), curProp.getColor()));
					sidePanel.setCashValue(p2.getCash(), owner);
					
					curPlayer.subtractCash(p2.getRentValue(curProp.getName(), curProp.getColor()));
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(p2.getTotalWealth(), owner);
				}
				else if(owner == 3)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + p3.getRentValue(curProp.getName(), curProp.getColor()) + " for rent.");
					
					p3.addCash(p3.getRentValue(curProp.getName(), curProp.getColor()));
					sidePanel.setCashValue(p3.getCash(), owner);
					
					curPlayer.subtractCash(p3.getRentValue(curProp.getName(), curProp.getColor()));
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(p3.getTotalWealth(), owner);
				}
				else if(owner == 4)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + p4.getRentValue(curProp.getName(), curProp.getColor()) + " for rent.");
					
					p4.addCash(p4.getRentValue(curProp.getName(), curProp.getColor()));
					sidePanel.setCashValue(p4.getCash(), owner);
					
					curPlayer.subtractCash(p4.getRentValue(curProp.getName(), curProp.getColor()));
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(p4.getTotalWealth(), owner);
				}
			} // end else
		} // end else if	
	} //end processLandingOnProperty

	
	
//-------------------------------------------------------------------------------------------------------------------------------
	
	public void processLandingOnUtility(boolean fromChance)
	{
// TEST:
/*		curProp.setOwnedBy(2);
		p2.addNewProperty(curProp.getName());
		p2.addNewProperty("WaterWorks");

		sidePanel.addProperty(curProp.getName(), 2);

		sidePanel.addProperty("WaterWorks", 2);
*/
// END TEST
		
		if(curProp.getOwnedBy() == 0)
		{
			displayPurchaseWindow(fromChance);
		}
		else if(curProp.getOwnedBy() == curPlayer.getPlayerNumber())
		{
			JOptionPane.showMessageDialog(null, "You already own this property!");
		}
		else if(fromChance == true)
		{
			int owner = curProp.getOwnedBy();
			JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
					+ "\nYou must roll the dice and pay 10 times the amount rolled.");
			
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				if(rollButtonClicked() == true)
				{
					sidePanel.resetRollButtonClicked();
					sidePanel.setRollButtonState(false);
					
					// wait so dice animation can finish rolling before assigning the new dice value
					while(true)
					{
						System.out.print(""); // statement added so Michael's code will work properly
						if(sidePanel.rollIsDone() == true)
						{
							break;
						}
					}
					break;
				}
			} // end while
			
			curPlayer.subtractCash(10 * getDiceValue());
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());

			if(owner == 1)
			{
				p1.addCash(10 * getDiceValue());
				sidePanel.setCashValue(p1.getCash(), owner);
				sidePanel.setTotalWealth(p1.getTotalWealth(), owner);
			}
			else if(owner == 2)
			{
				p2.addCash(10 * getDiceValue());
				sidePanel.setCashValue(p2.getCash(), owner);
				sidePanel.setTotalWealth(p2.getTotalWealth(), owner);
			}
			else if(owner == 3)
			{
				p3.addCash(10 * getDiceValue());
				sidePanel.setCashValue(p3.getCash(), owner);
				sidePanel.setTotalWealth(p3.getTotalWealth(), owner);
			}
			else if(owner == 4)
			{
				p4.addCash(10 * getDiceValue());
				sidePanel.setCashValue(p3.getCash(), owner);
				sidePanel.setTotalWealth(p3.getTotalWealth(), owner);
			}
		}
		else if(fromChance == false)
		{
			int owner = curProp.getOwnedBy();
			int total = 0;
			
			if(owner == 1)
			{
				total = p1.getNumUtility();
				if(total == 1)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + (4 * getDiceValue()) + " for rent.");
					curPlayer.subtractCash(4 * getDiceValue());
					p1.addCash(4 * getDiceValue());
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setCashValue(p1.getCash(), owner);
				}
				else if(total == 2)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + (10 * getDiceValue()) + " for rent.");
					curPlayer.subtractCash(10 * getDiceValue());
					p1.addCash(10 * getDiceValue());
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setCashValue(p1.getCash(), owner);	
				}

				sidePanel.setTotalWealth(p1.getTotalWealth(), owner);
				sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
			}
			else if(owner == 2)
			{
				total = p2.getNumUtility();
				if(total == 1)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + (4 * getDiceValue()) + " for rent.");
					curPlayer.subtractCash(4 * getDiceValue());
					p2.addCash(4 * getDiceValue());
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setCashValue(p2.getCash(), owner);
				}
				else if(total == 2)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + (10 * getDiceValue()) + " for rent.");
					curPlayer.subtractCash(10 * getDiceValue());
					p2.addCash(10 * getDiceValue());
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setCashValue(p2.getCash(), owner);	
				}

				sidePanel.setTotalWealth(p2.getTotalWealth(), owner);
				sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
			}
			else if(owner == 3)
			{
				total = p3.getNumUtility();
				if(total == 1)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + (4 * getDiceValue()) + " for rent.");
					curPlayer.subtractCash(4 * getDiceValue());
					p3.addCash(4 * getDiceValue());
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setCashValue(p3.getCash(), owner);
				}
				else if(total == 2)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + (10 * getDiceValue()) + " for rent.");
					curPlayer.subtractCash(10 * getDiceValue());
					p3.addCash(10 * getDiceValue());
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setCashValue(p3.getCash(), owner);
				}

				sidePanel.setTotalWealth(p3.getTotalWealth(), owner);
				sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
			}
			else if(owner == 4)
			{
				total = p4.getNumUtility();
				if(total == 1)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + (4 * getDiceValue()) + " for rent.");
					curPlayer.subtractCash(4 * getDiceValue());
					p4.addCash(4 * getDiceValue());
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setCashValue(p4.getCash(), owner);
				}
				else if(total == 2)
				{
					JOptionPane.showMessageDialog(null, "Player " + owner + " owns this property."
							+ "\nYou must pay $" + (10 * getDiceValue()) + " for rent.");
					curPlayer.subtractCash(10 * getDiceValue());
					p4.addCash(10 * getDiceValue());
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setCashValue(p4.getCash(), owner);
				}

				sidePanel.setTotalWealth(p4.getTotalWealth(), owner);
				sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
			} // end else if owner ==
		} // end else
	}
	
//-------------------------------------------------------------------------------------------------------------------------------

	public void displayPurchaseWindow(boolean fromChance)
	{
		purPan = new PurchasePanel(curProp.getName(), curProp.getPrice());
		// if ownedBy == 0, nobody owns it
		// display popup for purchasing this property
		JFrame frame = new JFrame ("Property Purchase?");
		frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frame.getContentPane().add(purPan);
		frame.pack();
		
		if(fromChance == true)
			frame.setLocation(100,312); // this should be changed to relative screen bounds but don't have time
		else if(fromChance == false)
			frame.setLocationRelativeTo(null);
		
		frame.setResizable(false);
		frame.setVisible(true);
		
		while(true)
		{
			System.out.print(""); // statement added so Michael's code will work properly
			if(purPan.getReturnValue() == 0)
			{
				// did not purchase
				frame.setVisible(false);
				frame.dispose();
				break;
			}
			else if(purPan.getReturnValue() == 1)
			{
				// did purchase
				frame.setVisible(false);
				frame.dispose();
				JOptionPane.showMessageDialog(null, "You purchased " + curProp.getName() + "!");
				curPlayer.subtractCash(curProp.getPrice());
				curPlayer.addNewProperty(curProp);
				
				sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
				sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
				
				sidePanel.addProperty(curProp.getName(), curPlayer.getPlayerNumber());
				curProp.setOwnedBy(curPlayer.getPlayerNumber());

				break;
			}
		} // end while
		purPan.resetReturnValue();
		
		// don't need this: if leaving it enabled all the time, the window will just display the fact that
		// the player owns no color groups so they cannot build
		if(curPlayer.checkGroups() == true)
		{
			sidePanel.setBuildButton(true);
			sidePanel.setCurPlayer(curPlayer);
		}
	} // end displayPurchasePanel

//-------------------------------------------------------------------------------------------------------------------------------	

	public void processLandingOnCorner()
	{
		// process corner actions
		if(curProp.getName() == "Go")
		{	
			// getting money for Go is handled in if statement way up above near dice roll
		}
		else if(curProp.getName() == "Jail")
		{	
			JOptionPane.showMessageDialog(null, "Just visiting!");
		}
		else if(curProp.getName() == "GoToJail")
		{	
			JOptionPane.showMessageDialog(null, "Go directly to Jail.\nDo not pass Go.  Do not collect $" + GOCASH);
			curPlayer.setLocation(10);
			curPlayer.setJailState(true);
			curPlayer.resetDoublesRolled();
			doublesWasRolled = false;
			lgbp.movePawn(40, curPlayer.getPlayerNumber());
			waitForPawnToMove();
		}
		else if(curProp.getName() == "FreeParking")
		{	
			JOptionPane.showMessageDialog(null, "Free Parking!  You collect $" + freeParkingFund);
			curPlayer.addCash(freeParkingFund);
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
			freeParkingFund = 0;
		}			
	}

//-------------------------------------------------------------------------------------------------------------------------------

	public void processLandingOnTax(boolean fromChance)
	{
		if(curProp.getName() == "LuxuryTax")
		{
			JOptionPane.showMessageDialog(null, "Player " + curPlayer.getPlayerNumber() + " paid $75 for Luxury Tax");
			curPlayer.subtractCash(75);	
			sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
			sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
		}
		else if(curProp.getName() == "IncomeTax")
		{
			taxPan = new TaxPanel(curProp.getName());
			// display popup for paying income tax
			JFrame frame = new JFrame ("Pay Income Tax");
			frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
			frame.getContentPane().add(taxPan);
			frame.pack();
			
			if(fromChance == true)
				frame.setLocation(100,312);
			else if(fromChance == false)
				frame.setLocationRelativeTo(null);
			
			frame.setResizable(false);
			frame.setVisible(true);
			
			while(true)
			{
				System.out.print(""); // statement added so Michael's code will work properly
				if(taxPan.getReturnValue() == 10)
				{
					// chose 10%
					frame.setVisible(false);
					frame.dispose();
					JOptionPane.showMessageDialog(null, "Player " + curPlayer.getPlayerNumber() + " paid 10% for Income Tax.");

					curPlayer.subtractCash(curPlayer.getTotalWealth() / 10);
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
					break;
				}
				else if(taxPan.getReturnValue() == 200)
				{
					// chose $200
					frame.setVisible(false);
					frame.dispose();
					JOptionPane.showMessageDialog(null, "Player " + curPlayer.getPlayerNumber() + " paid $200 for Income Tax.");
					curPlayer.subtractCash(200);
					sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
					sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
					break;
				}

			} // end while
			taxPan.resetReturnValue(); // doesn't matter b/c taxPan will always be created new?
		} // end else for IncomeTax

	}
	 
//-------------------------------------------------------------------------------------------------------------------------------

	public void wait(int time)
	{
		try 
		{
			Thread.currentThread().sleep(time);
		} 
		catch (InterruptedException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
//-------------------------------------------------------------------------------------------------------------------------------

	public void waitForPawnToMove()
	{
		while(true)
		{
			System.out.print(""); // statement added so Michael's code will work properly
			if(lgbp.pawnsDone() == true)
			{
				break;
			}
		}
	}
	
//-------------------------------------------------------------------------------------------------------------------------------

	public void processJailOptions()
	{
// TEST
/*		curPlayer.setJailFreeChance(true);
		sidePanel.addJailFreeCard("jailfreechance", curPlayer.getPlayerNumber());
		//curPlayer.setJailFreeCommChest(true);
*/
// END TEST
		
		jailPan = new JailPanel(curPlayer);
		// display popup for jail options
		JFrame frame = new JFrame ("Jail Options");
		frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frame.getContentPane().add(jailPan);
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setResizable(true);
		frame.setVisible(true);
		
		while(true)
		{
			System.out.print(""); // statement added so Michael's code will work properly
			// chose RollDice
			if(jailPan.getReturnValue() == 0)
			{
				frame.setVisible(false);
				frame.dispose();
				JOptionPane.showMessageDialog(null, "Roll dice for doubles!");
				sidePanel.setRollButtonState(true);
				
				while(true)
				{
					System.out.print(""); // statement added so Michael's code will work properly
					if(rollButtonClicked() == true)
					{
						sidePanel.resetRollButtonClicked();
						sidePanel.setRollButtonState(false);
						//wait(800);
						while(true)
						{
							System.out.print(""); // statement added so Michael's code will work properly
							if(sidePanel.rollIsDone() == true)
							{
								break;
							}
						}
						break;
					}
				}
				
				// if doubles rolled, get out of jail, else stay in jail
				if(sidePanel.diceIsDoubles() == true)
				{
					JOptionPane.showMessageDialog(null, "Success!  You got out of jail!");
					curPlayer.setJailState(false);
					curPlayer.resetJailTurns();
					curPlayer.resetDoublesRolled();
					doublesWasRolled = false;
					stillInJail = false;
					justOutOfJailWithDoubles = true;
				}
				else if(sidePanel.diceIsDoubles() == false)
				{
					if(curPlayer.getJailTurns() < 3)
					{
						JOptionPane.showMessageDialog(null, "Sorry, still in jail!");
						stillInJail = true;
						justOutOfJailWithDoubles = false;
					}
					else if(curPlayer.getJailTurns() == 3)
					{
						JOptionPane.showMessageDialog(null, "You paid $50 and are now out of jail.");
						curPlayer.subtractCash(50);
						curPlayer.subtractTotalWealth(50);
						sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
						sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
						curPlayer.setJailState(false);
						curPlayer.resetJailTurns();
						stillInJail = false;
						justOutOfJailWithDoubles = true;
					}
				}
				
				break;
			}
			// chose pay fine
			else if(jailPan.getReturnValue() == 1)
			{
				frame.setVisible(false);
				frame.dispose();
				curPlayer.subtractCash(50);
//UPDATE PLAYER'S TOTAL WORTH				
				sidePanel.setCashValue(curPlayer.getCash(), curPlayer.getPlayerNumber());
				sidePanel.setTotalWealth(curPlayer.getTotalWealth(), curPlayer.getPlayerNumber());
				
				JOptionPane.showMessageDialog(null, "Roll the dice to move out of Jail!");
				sidePanel.setRollButtonState(true);
				curPlayer.setJailState(false);
				curPlayer.resetJailTurns();
				curPlayer.resetDoublesRolled();
				doublesWasRolled = false;
				stillInJail = false;
				justOutOfJailWithDoubles = false;
/*				while(true)
				{
					System.out.print("waiting for "); // statement added so Michael's code will work properly
					if(rollButtonClicked() == true)
					{
						sidePanel.resetRollButtonClicked();
						sidePanel.setRollButtonState(false);
						//wait(800);
						while(true)
						{
							System.out.print(""); // statement added so Michael's code will work properly
							if(sidePanel.rollIsDone() == true)
							{
								break;
							}
						}
						break;
					}
				}
*/
				//curPlayer.setLocation(curPlayer.getLocation() + getDiceValue());asdf
				break;
			}
			// chose to use chance card to get out of jail free
			else if(jailPan.getReturnValue() == 2 || jailPan.getReturnValue() == 3)
			{
				frame.setVisible(false);
				frame.dispose();
				
				if(jailPan.getReturnValue() == 2)
				{
					curPlayer.setJailFreeChance(false);
					sidePanel.removeJailFreeCard("jailfreechance", curPlayer.getPlayerNumber());
				}
				else if(jailPan.getReturnValue() == 3)
				{
					curPlayer.setJailFreeCommChest(false);
					sidePanel.removeJailFreeCard("jailfreechest", curPlayer.getPlayerNumber());
				}

				curPlayer.setJailState(false);
				curPlayer.resetJailTurns();
				curPlayer.resetDoublesRolled();
				
				JOptionPane.showMessageDialog(null, "Roll the dice to move out of Jail!");
				sidePanel.setRollButtonState(true);
				// once function exits here the code will pick up the next dice roll for
				// the curPlayer (I think)
				break;
			}
				
			
		} // end while
	
	} // end processJailOptions

//-------------------------------------------------------------------------------------------------------------------------------
	
	public void checkIfDoublesWasRolled()
	{
		if(doublesWasRolled == false)
		{
			if(curPlayer.getPlayerNumber() == 1)
			{
				curPlayer = p2;
				curPlayerNum = 2;
			}
			else if(curPlayer.getPlayerNumber() == 2)
			{
				curPlayer = p3;
				curPlayerNum = 3;
			}
			else if(curPlayer.getPlayerNumber() == 3)
			{
				curPlayer = p4;
				curPlayerNum = 4;
			}
			else if(curPlayer.getPlayerNumber() == 4)
			{
				curPlayer = p1;
				curPlayerNum = 1;
				totalNumTurns++;
			}
		}
		else if(doublesWasRolled == true)
		{
			JOptionPane.showMessageDialog(null, "Player " + curPlayer.getPlayerNumber() + " rolled doubles.");
		}
	}

//-------------------------------------------------------------------------------------------------------------------------------
	
//-------------------------------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------------------------



} // end class PlayMonopoly